﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Input;
using MouseExtender.Logic.Enums;

namespace MouseExtender.Logic.Converters
{
    public class MouseExtenderButtonHelper
    {

        public static ModifierKeys GetModifierKeys(MouseExtenderButton value)
        {
            ModifierKeys keys = ModifierKeys.None;

            if ((value & MouseExtenderButton.CtrlKey) == MouseExtenderButton.CtrlKey)
                keys |= ModifierKeys.Control;
            if ((value & MouseExtenderButton.AltKey) == MouseExtenderButton.AltKey)
                keys |= ModifierKeys.Alt;
            if ((value & MouseExtenderButton.ShiftKey) == MouseExtenderButton.ShiftKey)
                keys |= ModifierKeys.Shift;

            return keys;
        }

        public static MouseButton GetMouseButton(MouseExtenderButton value)
        {
            if ((value & MouseExtenderButton.MiddleButton) == MouseExtenderButton.MiddleButton)
                return MouseButton.Middle;
            if ((value & MouseExtenderButton.LeftButton) == MouseExtenderButton.LeftButton)
                return MouseButton.Left;
            if ((value & MouseExtenderButton.RightButton) == MouseExtenderButton.RightButton)
                return MouseButton.Right;
            if ((value & MouseExtenderButton.XButton1) == MouseExtenderButton.XButton1)
                return MouseButton.XButton1;
            if ((value & MouseExtenderButton.XButton2) == MouseExtenderButton.XButton2)
                return MouseButton.XButton2;

            throw new ApplicationException("Value does not contains any valid mouse button");
        }

        public static ModifierKeys ConvertToModifierKeys(MouseExtenderButton buttons)
        {
            ModifierKeys value = MouseExtenderButtonHelper.GetModifierKeys(buttons);
            return value;
        }

        public static MouseButton ConvertToMouseButton(MouseExtenderButton buttons)
        {
            MouseButton value = MouseExtenderButtonHelper.GetMouseButton(buttons);
            return value;
        }
    }
}
